package ui.frame.dialog;

import java.awt.event.ActionEvent;

import ui.Utility;
import ui.frame.GTFrame;
import ui.frame.GTextbook;
import ui.view.NodeInfo;
import ui.view.GTView;
import ui.view.IndexTreeView;
import static constants.GTextbookConstants.Category;
import static constants.GTextbookConstants.language;

public class InsertCategoryDialog extends CategoryDialog{

	public InsertCategoryDialog(GTextbook theApp,int language){
		super(theApp, language);
	}
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		if(e.getSource() == cancel){
			this.dispose();
		}
		if(e.getSource() == ok){
			//get the information input by users
			if(store("Category")){
				String roleField = getRolePanel().getTextField().getText();
				String nameField = getNamePanel().getTextField().getText();
				String role = Utility.getKnowledgeNameFromInput(roleField);
				String name = Utility.getKnowledgeNameFromInput(nameField);
			
				NodeInfo NodeInfo = new NodeInfo(role, name, language.getNum());
				((IndexTreeView)(((GTView)(theApp.getView())).getIndexTabbedPane().getSelectedComponent())).getIndexTree().insertObject(NodeInfo);
				this.dispose();
			}
		}
	}
}
